<?php
//////////////////////////////////////////////////////
// GPAC Database is Copyright 2002 Colin Todd       //
// Written by Colin Todd - All rights reserved.     //
//                                                  //
// colintodd@myfastmail.com                         //
//////////////////////////////////////////////////////

//check user is logged in
include_once('_includes/master_include.php');

$root = './';
include($root . 'include/header.php');
include($root . 'include/dbconnect.php');

$result = mysql_query("SELECT * FROM $family ORDER BY FamilyShortName",$PACTS_cfg->dblink);
//echo mysql_affected_rows($db)." rows affected!";


$listfilter = "";
$listfilter = @$_GET['listfilter'];
$WhereFilter = "";
$listfilter_htmlcode = "listfilter=$listfilter&";

$link = "Fmly_az_list.php?";

$WhereFilter = getListHeader($listfilter_htmlcode,"","Fmly_az_list.php","Fmly_allentries.php","Families",$listfilter,&$WhereFilter);
$link = "Fmly_allentries.php?";
$WhereFilter = "TRUE ".$WhereFilter;
$Print_string = "<table cellpadding=2 cellspacing=1 border=0>"; 

$alternate = "2"; 
$resultsnumber = 0;

while ($row = mysql_fetch_array($result)) { 

	$FamilyId = $row["FamilyId"]; 
	$FilterCount = 0;
	$sqlFilterCount = "SELECT IndividualId FROM Individual Where FamilyId=$FamilyId AND $WhereFilter";
	if(strlen($listfilter)>0) {
		$resultIndv = mysql_query($sqlFilterCount ,$PACTS_cfg->dblink);
		$FilterCount = mysql_num_rows($resultIndv );
	}

//		echo "$FilterCount :: $sqlFilterCount <p>";
	if($FilterCount > 0 or strlen($listfilter)==0) {
		$resultsnumber = $resultsnumber + 1;
		$shortname = $row["FamilyShortName"]; 

		$shortname = getFormattedFamilyShortName($FamilyId,$PACTS_cfg->dblink," ",$shortname);
		$HeadOfFamily = getFamilyRoleNameList($FamilyId,$PACTS_cfg->dblink," + ","Head Of Family");

		
		$sql_c = "SELECT RoleTypeCode, Count(RoleTypeCode) as Count ";
		$sql_c .= "FROM Individual WHERE FamilyId=$FamilyId ";
		$sql_c .= "GROUP BY RoleTypeCode; ";

		$ChildrenCount = 0;
		$OtherCount = 0;
		$result_c = mysql_query($sql_c ,$PACTS_cfg->dblink);
		while ($row_c = mysql_fetch_array($result_c)) { 

			if($row_c['RoleTypeCode']=="Child") {
				$ChildrenCount = $row_c['Count'];		
			}			
			if($row_c['RoleTypeCode']=="Other") {
				$OtherCount = $row_c['Count'];		
			}			
		
		}// end while

		$Print_stringXX = "";
		$Print_stringXX .= "$shortname <i>($HeadOfFamily";
		if($ChildrenCount>0) {
			if(strlen($HeadOfFamily)>0) {
				$Print_stringXX .= " +";				
			} 
			$Print_stringXX .= " ".$ChildrenCount."C";
		}

		if($OtherCount>0) {
			if(strlen($HeadOfFamily)>0) {
				$Print_stringXX .= " +";				
			}
			$Print_stringXX .= " ".$OtherCount."O";
		}
		$Print_stringXX .= ")</i>";
		$Print_string .= getFmlyNavBar( "", $FamilyId, TRUE, TRUE, TRUE, "Fmly_allentries","",TRUE,TRUE,$Print_stringXX);
		$Print_string .= "</tr>";
	}
} 
$Print_string .= "</table>";

echo "&nbsp;<b>Number of entries: $resultsnumber</b><br />";
echo $Print_string; 
$PACTS_cfg->end_div_main();

include($root . 'include/footer.php');
?>